package com.chauncy.DMS.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import util.List2Json1.List2Json1;

import com.chauncy.DMS.bean.StuDormInfoBean;
import com.chauncy.DMS.dao.ManagerDaoImplement;

public class SelectStuDormInfoByNameAndNumberServlet extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			ManagerDaoImplement daoImplement = new ManagerDaoImplement();
			//获取ajax 请求servlet时传递过来的参数
			String sName = request.getParameter("stuName");
			String sNumber = request.getParameter("stuNub");
			//System.out.println("request.getParameter:"+sName+sNumber);
			List<StuDormInfoBean> infoBeans = new ArrayList<StuDormInfoBean>();
			try {	
				infoBeans = daoImplement.selectSDIByNameAndNumber(sName, sNumber);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			if(infoBeans.size() > 0 && infoBeans != null){
				//将list转换成json传递
				JSONArray array =  JSONArray.fromObject(infoBeans);
				response.getWriter().print(array);
			}else{
				System.out.println("/+error_info+/+infoBeans is null");
			}
		
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		
	}

}
